
function GetRequest() {
		   var url = location.search; 
		  if (url.indexOf("?")!= -1) {
		     url=url.substr(url.indexOf("id=")+3);
		   }
		   return url;}

function getCookie(sName)
{
	
var aCookie = document.cookie.split(";");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
function getUserById(){
	let userid=getCookie("user");
	let au=new AjaxUtils;
	let name="";
	 param="login.servlet?param=getUserById&id="+userid;									
    au.ajaxRequest(param,(xhr)=>{
    	
    	let json=JSON.parse(xhr.responseText);
    	name=json.user.userName;
    	
    });
    return	name;
}

function init(){
	
	document.getElementById("publicChat").href="login.servlet?param=publicchat&name="+getUserById();
	
	document.getElementById("headicon").src="usermessageadmin.servlet?param=getIcon&id="+getCookie("user");
	let au=new AjaxUtils;
	 param="blog.servlet?param=getAllBlogType";									// 请求接收博客类型列表
     au.ajaxRequest(param,(xhr)=>{
    	 var json=JSON.parse(xhr.responseText);
    	 let data=json.data;
    	 let blogdata=json.blogdata;
    	 
    	let point= document.getElementById("ssinsertpoint");
    	for(let i=0;i<data.length;i++){
			let li1=document.createElement("li");
			li1.className="leftMenuLi1";
			li1.innerHTML=data[i].typename;
			let div=document.createElement("div");
			div.className="leftMenuLi1_image";
			li1.appendChild(div);
			point.appendChild(li1);
			let ul=document.createElement("ul");
			ul.id="leftSubMenu";
			for(let j=0;j<blogdata.length;j++){
				if(data[i].typename==blogdata[j].type_name){
				let li=document.createElement("li");
				li.className="leftMenuLi2";
				let a=document.createElement("a");
				a.className="navigate";
				a.target="mainPage";
				a.href="blog.servlet?param=jumptoarticle&id="+blogdata[j].blog_id;
				a.innerHTML=blogdata[j].blog_name;
				li.appendChild(a);
				ul.appendChild(li);
				}
			point.appendChild(ul);
			}
		}	
    	
    	
    	 
     });
    window.onscroll=function(){
        
        var he = document.documentElement.scrollTop||document.body.scrollTop;
        var message = document.getElementById('message');
        if(he>100){
            message.className="bb";
        }
        else if(he<100) {
            message.className="bbf";
        }
    }
    Array.from(document.querySelectorAll(".leftMenuLi1_image")).forEach((item)=>{
        item.addEventListener("click",(event)=>{
            let currentNode=event.target.parentElement.nextElementSibling;
            if(currentNode.hidden==false){
                item.style.transform="rotate(90deg)";
                currentNode.hidden=true;
            }else{
                item.style.transform="rotate(-90deg)";
                currentNode.hidden=false;
            }
        },false);
    });
}
window.addEventListener("load",init,false);
